package com.badibadi.fragment;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;

import net.tsz.afinal.FinalBitmap;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.android.volley.toolbox.NetworkImageView;
import com.badibadi.activity.AddingRecordFirstActivity;
import com.badibadi.activity.LogReadingDanjiActivity;
import com.badibadi.activity.ModifyTheRecordDanjiActivity;
import com.badibadi.activity.PicturePreviewActivity;
import com.badibadi.activity.PinyinSeeRecordParticipantsActivity;
import com.badibadi.adapter.Gridview3Adapter;
import com.badibadi.adapter.PinLunGYAdapter;
import com.badibadi.adapter.PinLunGYAdapter.PinLunInterface;
import com.badibadi.fragment.LogReadingFragment0.LogReadingFragment0Adapter;
import com.badibadi.fragment.LogReadingFragment0.ViewHolder;
import com.badibadi.fragment.LogReadingFragment0.setActivityView;
import com.badibadi.infos.Article_img_Model;
import com.badibadi.infos.BrowseAllPhoto_Model;
import com.badibadi.infos.Discuss;
import com.badibadi.infos.Img;
import com.badibadi.infos.LogReadingDanji_Model;
import com.badibadi.infos.Record_Info_Model;
import com.badibadi.infos.Record_Info_Model_1;
import com.badibadi.infos.Record_Info_Model_2;
import com.badibadi.infos.Results;
import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Convert;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.ShareSDKTools;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.VolleyTools;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.SinaExpressionActivity;
import com.libjph.util.JsonUtil;
import com.libjph.util.StringUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.test.pic.TestActivity;
import com.view.my_view.MyGridView;
import com.wyy.twodimcode.FinishListener;
//picture_gridView bianji ShareSDKTools dijiji
//send  onCreateView 看参加人数  bianji article_area ll_share picture_gridView ll_share AddCity r_num

public class LogReadingDanjiFragment0 extends BaseFragment {// ll_share Convert

	static LogReadingDanjiFragment0 logReadingDanjiFragment0;
	// 编辑和删除的
	private PopupWindow pop;
	private PinLunGYAdapter pinLunGYAdapter; // content
	private String aid = "121";// 单记的id
	private String f_uid = "1";// 该条记录的人的id,（注意：不是用户的id）
	private String rid;

	private String cid;// 俱乐部的id 如果是个人的记录为null
	private String admin_id;// 俱乐部管理员id 如果是个人的为null
	// bun.putString("cid", cid);
	// bun.putString("admin_id", admin_id);
	//
	private int position = 1;
	private String TAG = "LogReadingDanjiFragment0";
	private LogReadingDanji_Model logReadingDanji_Model;
	private FinalBitmap finalBitmap;
	private DisplayImageOptions options;

	private Discuss discuss;
	boolean is_praise = false;

	ViewHolder holder;
	private String uid;
	private String title = null;
	private Handler handler = new Handler() {
		@SuppressLint("NewApi")
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
				}
				break;
			case 2:
				Utils.ExitPrgress(getActivity());
				try {
					// f_uid = getArguments().getString("f_uid");
					// //
					// rid = getArguments().getString("rid");
					// cid = getArguments().getString("cid");
					// admin_id = getArguments().getString("admin_id");
					// position = getArguments().getInt("position", 1);
					f_uid = logReadingDanji_Model.getRecord_uid();
					rid = logReadingDanji_Model.getRecord_id();
					cid = logReadingDanji_Model.getRecord_clubId();
					admin_id = logReadingDanji_Model.getClubAdminUid();
					position = Integer.parseInt(logReadingDanji_Model
							.getR_num());
					is_praise("record_article", aid);
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 3:
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb12));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 4:// 删除单记
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(), ""
							+ msg.getData().getString("message", ""));
					if (msg.getData().getBoolean("ret") == true) {
						Constants.is_shuaxin = true;
						getActivity().finish();
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 5:// 评论成功
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(
							getActivity(),
							getResources().getString(
									R.string.wx_pinglun_success));
					// Intent intent=new
					// Intent(getActivity(),LogReadingDanjiActivity.class);
					// // bun.putString("aid", aid);
					// // bun.putInt("position", position);
					// // bun.putString("rid", rid);
					// intent.put("aid", value);
					// intent.put("position",position);

					// LoadingInterNet();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 6:// 评论成功
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.wx_pinglun_false));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 7:// 这里才开始初始化view
				Utils.ExitPrgress(getActivity());
				try {
					initView();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 8:// 点赞成功
				Utils.ExitPrgress(getActivity());

				try {
					LoadingInterNet();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 9:// 点赞失败
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.wx_zan_false));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 10:// 是否已经赞了
				Utils.ExitPrgress(getActivity());
				try {
					is_praise = true;
					initDisscuss();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 11:
				Utils.ExitPrgress(getActivity());
				try {
					is_praise = false;
					initDisscuss();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			default:
				break;
			}
		}

	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		finalBitmap = FinalBitmap.create(getActivity());
		finalBitmap.configLoadfailImage(R.drawable.noimage);
		finalBitmap.configLoadingImage(R.drawable.noimage);

		aid = getArguments().getString("aid");

		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();
		uid = Utils.getUid(getActivity());
		LoadingInterNet();

	}

	private void setPopWindow() {
		View root = LayoutInflater.from(getActivity()).inflate(
				R.layout.log_popwindow_danji, null);
		pop = new PopupWindow(root, DisplayUtil.dip2px(getActivity(), 65),
				DisplayUtil.dip2px(getActivity(), 100));

		pop.setBackgroundDrawable(new BitmapDrawable());
		pop.setFocusable(true);
		pop.setTouchable(true);
		pop.setOutsideTouchable(true);
		holder.delete = (TextView) root.findViewById(R.id.delete);
		// 删除
		holder.delete.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// deleteRecord();
				if (!Utils.getUid(getActivity()).equals("")) {

					Dialog dialog = new Dialog();
					dialog.CreateDialog(getActivity(), getResources()
							.getString(R.string.wx_txt_63), getResources()
							.getString(R.string.wx_txt_64));
					dialog.setOnDialogClistener(new Dialog.DialogClistener() {

						@Override
						public void ret() {
							// TODO Auto-generated method stub

						}

						@Override
						public void ok() {
							// TODO Auto-generated method stub

							if (cid != null)// 俱乐部的
							{
								if (admin_id != null) {
									if (admin_id.equals(""
											+ Utils.getUid(getActivity()))
											|| f_uid.equals(""
													+ Utils.getUid(getActivity()))) {
										delete_article();
									} else {
										Utils.showMessage(
												getActivity(),
												getResources().getString(
														R.string.wx_txt_65));
									}
								}

							} else if (cid == null)// 个人的
							{
								if (f_uid.equals(Utils.getUid(getActivity()))) {
									delete_article();
								} else {
									Utils.showMessage(
											getActivity(),
											getResources().getString(
													R.string.wx_txt_66));
								}

							}
						}

					});
				} else {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb10));
				}
			}
		});

		holder.bianji = (TextView) root.findViewById(R.id.bianji);
		// 编辑
		holder.bianji.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!Utils.getUid(getActivity()).equals("")) {

					if (cid != null)// 俱乐部的
					{
						if (admin_id != null) {
							if (admin_id.equals(""
									+ Utils.getUid(getActivity()))
									|| f_uid.equals(""
											+ Utils.getUid(getActivity()))) {
								Intent intent = new Intent(getActivity(),
										ModifyTheRecordDanjiActivity.class);
								intent.putExtra("aid", aid);
								intent.putExtra("cid", cid);
								intent.putExtra("rid", rid);
								intent.putExtra("dijiji", "" + position);// 第几记
								// intent.putExtra(name, value)
								//
								startActivity(intent);
								getActivity().finish();
							} else {
								Utils.showMessage(getActivity(), getResources()
										.getString(R.string.wx_txt_65));
							}
						}

					} else if (cid == null)// 个人的
					{
						if (f_uid.equals(Utils.getUid(getActivity()))) {
							Intent intent = new Intent(getActivity(),
									ModifyTheRecordDanjiActivity.class);
							intent.putExtra("aid", aid);
							intent.putExtra("rid", rid);
							intent.putExtra("dijiji", "" + position);// 第几记
							// intent.putExtra(name, value)
							startActivity(intent);
							getActivity().finish();
						} else {
							Utils.showMessage(getActivity(), getResources()
									.getString(R.string.wx_txt_67));
						}

					}
				} else {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb10));
				}

			}
		});

	}

	private void initDisscuss() {
		ShowDisscuss(aid, "record_article", "99999999",
				Dialog.getSystemLanguageTypegy(getActivity()));
	}

	/**
	 * 查看某个动态的评论列表---get(必需--配合语言)
	 * 
	 * @param $id
	 *            //(必需)需要查看的动态评论ID
	 * @param $type
	 *            //(必需)动态的类型---photo_img：图片，photo：相册，record_article：记录（记），
	 *            humor_trends:心情动态，club：俱乐部，activity：活动
	 * @param $disNum
	 *            //显示的一级评论数量
	 * @param $l
	 *            ;（必需）//zh-cn 为中文简体，zh-tw 中文繁体 en-us 英文
	 */
	private void ShowDisscuss(final String id, final String type,
			final String disNum, String l) {
		Utils.showPrgress(getActivity());
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();

				// String content = Utils.sendRequest(map, Constants.BadiUrl
				// + "friends");
				String l = Dialog.getSystemLanguageTypegy(getActivity());
				String content = Utils.getRequest(Constants.BadiUrl_1
						+ "commonality/showDisscuss?id=" + id + "&type=" + type
						+ "&disNum=" + disNum + "&l=" + l);
				// ();
				// + "&page=" + page + "&pageNum=" + 10);
				//
				if (content != null) {
					Results results = Utils.checkResult_NNN(getActivity(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
						//
						try {
							discuss = JsonUtil.getEntityByJsonString(
									results.getRetmsg(), Discuss.class);
							// showDisscuss=discuss.getDiscu().get(0);
							// activityReadingModel=JsonUtil.getEntityByJsonString(results.getRetmsg(),
							// ActivityReadingModel.class);
							handler.sendEmptyMessage(7);
						} catch (Exception e) {

						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	/**
	 * 获取数据
	 */
	private void LoadingInterNet() {
		Utils.showPrgress(getActivity());
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				// String content = Utils.sendRequest(map, Constants.BadiUrl
				// + "friends");
				// 记录id
				String content = Utils.getRequest(Constants.BadiUrl
						+ "show_article?aid=" + aid + "&uid=" + uid);
				//
				// + "&uid=" + Utils.getUid(getActivity()));
				// (Constants.BadiUrl + "friends?uid=" + id
				// + "&page=" + page + "&pageNum=" + 10);
				//
				if (content != null) {
					Results results = Utils.checkResult_NNN(getActivity(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
						//
						// "Index/show_article结果是:" + results.getRetmsg());
						try {
							logReadingDanji_Model = JSONUtils
									.getEntityByJsonString(results.getRetmsg(),
											LogReadingDanji_Model.class);

							handler.sendEmptyMessage(2);
						} catch (Exception e) {

						}
					} else {

						handler.sendEmptyMessage(3);
					}
				} else {

					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	// private void AddCity(String name, LinearLayout v) {
	// Button button = new Button(getActivity());
	// button.setText(name);
	// button.setBackgroundResource(R.drawable.shape_blue_circular_bead_100);
	// //
	// button.setLayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,DisplayUtil.dip2px(getActivity(),
	// // 40));
	// button.setTextColor(getActivity().getResources()
	// .getColor(R.color.white));
	// v.addView(button);
	// }

	/**
	 * View视图的id
	 */
	public void initViewID(View view, ViewHolder holder) {
		// TODO Auto-generated method stub
		holder.listview_pinlun = (ListView) view
				.findViewById(R.id.listview_pinlun);
		holder.dijiji = (TextView) view.findViewById(R.id.dijiji);
		holder.startTimeandendTime = (TextView) view
				.findViewById(R.id.startTimeandendTime);
		holder.canjiarenshu = (TextView) view.findViewById(R.id.canjiarenshu);
		holder.ll_zhanName = (LinearLayout) view.findViewById(R.id.ll_zhanName);
		holder.content = (TextView) view.findViewById(R.id.content);
		holder.tuxian1 = (ImageView) view.findViewById(R.id.tuxian1);
		holder.canjiazhehead = (LinearLayout) view
				.findViewById(R.id.canjiarenhead);
		holder.admire = (TextView) view.findViewById(R.id.admire);
		holder.discuss = (TextView) view.findViewById(R.id.discuss);
		holder.share = (TextView) view.findViewById(R.id.share);
		holder.zanPeople = (TextView) view.findViewById(R.id.zanPeople);
		holder.listview_pinlun = (ListView) view
				.findViewById(R.id.listview_pinlun);
		// holder.delete = (TextView) view.findViewById(R.id.delete);
		holder.picture_gridView = (GridView) view
				.findViewById(R.id.picture_gridView);
		holder.send_content = (EditText) view.findViewById(R.id.send_content);
		holder.send = (Button) view.findViewById(R.id.send);
		holder.lshare = (ImageView) view.findViewById(R.id.ll_share);// share
		holder.all_zan_people = (LinearLayout) view
				.findViewById(R.id.all_zan_people);
		// holder.bianji = (TextView) view.findViewById(R.id.bianji);
		holder.iv_zan = (ImageView) view.findViewById(R.id.iv_zan);
		holder.biaoqing = (ImageView) view.findViewById(R.id.biaoqing);
		holder.xiala = (ImageView) view.findViewById(R.id.xiala);
	}

	protected void initView() {
		// TODO Auto-generated method stub
		setPopWindow();
		holder.xiala.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				pop.showAsDropDown(v);
			}
		});

		// // 编辑
		// holder.bianji.setOnClickListener(new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// if (cid != null)// 俱乐部的
		// {
		// if (admin_id != null) {
		// if (admin_id.equals("" + Utils.getUid(getActivity()))
		// || f_uid.equals(""
		// + Utils.getUid(getActivity()))) {
		// Intent intent = new Intent(getActivity(),
		// ModifyTheRecordDanjiActivity.class);
		// intent.putExtra("aid", aid);
		// intent.putExtra("cid", cid);
		// // intent.putExtra("dijiji",
		// // Convert.convert(position));//第几记
		// // intent.putExtra(name, value)
		// startActivity(intent);
		// } else {
		// Utils.showMessage(getActivity(), "你没有权限做此操作！");
		// }
		// }
		//
		// } else if (cid == null)// 个人的
		// {
		// if (f_uid.equals(Utils.getUid(getActivity()))) {
		// Intent intent = new Intent(getActivity(),
		// ModifyTheRecordDanjiActivity.class);
		// intent.putExtra("aid", aid);
		// // intent.putExtra("dijiji",
		// // Convert.convert(position));//第几记
		// // intent.putExtra(name, value)
		// startActivity(intent);
		// } else {
		// Utils.showMessage(getActivity(), "这不是您的记录,不能编辑!");
		// }
		//
		// }
		//
		// }
		// });
		// ll_share

		holder.lshare.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				/**
				 * 
				 * @param context
				 *            上下文
				 * @param title
				 *            (标签)
				 * @param text
				 *            （内容）
				 * @param titleUrl
				 *            (不传)
				 * @param ImageUrl
				 *            下面是 站内分享要传的
				 * @param type
				 *            分享类型 心情动态：humor_trends 活动：activity 俱乐部：club
				 * 
				 * @param $share_id
				 *            被分享的内容ID（心情动态ID 或 活动ID 或 俱乐部ID）
				 * @param $dul
				 *            分享谁的心情动态、活动、俱乐部-------发布被分享的动态原始数据的用户ID
				 * @param $cid
				 *            俱乐部ID---该参数只在俱乐部动态中才有非0值，对于个人中心动态中的$cid=0
				 * 
				 *            站外分享返回相应链接----POST
				 * @param $type2
				 *            分享类型 photo_img：相片 humor_trends:心情动态
				 *            record_article：记录（记） club:创建的俱乐部 activity：发起的活动
				 *            friend：朋友
				 * 
				 * 
				 * 
				 */
				if (!Utils.getUid(getActivity()).equals("")) {

					if (logReadingDanji_Model != null) {
						if (logReadingDanji_Model.getImg() != null
								&& !logReadingDanji_Model.getImg().isEmpty()) {
							if (!StringUtil.isNullOrEmpty(logReadingDanji_Model
									.getImg().get(0).getPath())) {
								String m = "0";
								ShareSDKTools.ShowOneKeyShare(getActivity(),
										"分享",
										logReadingDanji_Model.getContent(), "",
										Constants.BadiDownImgUrl
												+ "/"
												+ logReadingDanji_Model
														.getImg().get(0)
														.getPath(), null, aid,
										logReadingDanji_Model.getRecord_uid(),
										m, "record_article");
							} else {
								String m = "0";
								ShareSDKTools.ShowOneKeyShare(getActivity(),
										"分享",
										logReadingDanji_Model.getContent(), "",
										"", null, aid,
										logReadingDanji_Model.getRecord_uid(),
										m, "record_article");
							}

						} else {
							ShareSDKTools.ShowOneKeyShare(getActivity(), "分享",
									logReadingDanji_Model.getContent(), "", "",
									null, null, aid,
									logReadingDanji_Model.getRecord_uid(),
									"record_article");
						}
					}
				} else {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb10));
				}
			}
		});
		// 这里是评论的
		if (discuss != null) {
			// pinLunGYAdapter=new
			// pinLunGYAdapter(getActivity(),logReadingDanji_Model.getDiscussInfo());
			pinLunGYAdapter = new PinLunGYAdapter(getActivity(), discuss, aid,
					"record_article", f_uid, holder.send_content, holder.send);
			pinLunGYAdapter
					.setOnRefreshPingLunInterface(new PinLunGYAdapter.PinLunInterface() {

						@Override
						public void DeletePingLunRefresh() {
							// TODO Auto-generated method stub
							LoadingInterNet();
						}
					});
			holder.listview_pinlun.setAdapter(pinLunGYAdapter);
		}
		// 第几记
		holder.dijiji.setText(getResources().getString(R.string.l_xb42)
				+ position// Convert.convert()
				+ getResources().getString(R.string.wx_ji));
		// 开始时间和结束时间
		String a = logReadingDanji_Model.getStart_time().replaceAll("-", ".");
		String b = logReadingDanji_Model.getEnd_time().replaceAll("-", ".");
		holder.startTimeandendTime.setText(a + " - " + b);
		// 内容
		if (!StringUtil.isNullOrEmpty(logReadingDanji_Model.getContent())) {
			// holder.content.setText(""+logReadingDanji_Model.getContent());
			new HtmlUtils(getActivity(), holder.content, ""
					+ logReadingDanji_Model.getContent()).showTextView();
		}

		// 参加人数
		holder.canjiarenshu.setText("("
				+ logReadingDanji_Model.getJoinuserNum() + ")");
		final List<Record_Info_Model_2> info = new ArrayList<Record_Info_Model_2>();
		if (logReadingDanji_Model.getJoinuser() != null)
			info.addAll(logReadingDanji_Model.getJoinuser());

		// 参加者头像的
		if (logReadingDanji_Model.getJoinuser() != null) {
			holder.canjiazhehead.removeAllViews();
			holder.canjiazhehead.setGravity(Gravity.CENTER_VERTICAL
					| Gravity.CENTER_HORIZONTAL);

			for (int j = 0; j < logReadingDanji_Model.getJoinuser().size(); j++) {

				// info.addAll(arg0)(log);
				LayoutInflater inflater = LayoutInflater.from(getActivity());
				View view = inflater.inflate(R.layout.aah, null);
				ImageView iv = (ImageView) view.findViewById(R.id.aah);
				iv.setPadding(DisplayUtil.dip2px(getActivity(), 1), 0,
						DisplayUtil.dip2px(getActivity(), 1), 0);
				iv.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(getActivity(),
								PinyinSeeRecordParticipantsActivity.class);
						intent.putExtra("info", (Serializable) info);
						startActivity(intent);
						getActivity().overridePendingTransition(
								R.anim.slide_left, R.anim.slide_right);
					}
				});
				try {
					// finalBitmap.display(iv,
					// Constants.BadiDownImgUrl+"/"+logReadingDanji_Model.getJoinuser().get(j).getHead(),DisplayUtil.dip2px(getActivity(),
					// 49),DisplayUtil.dip2px(getActivity(), 49));
					ImageLoader.getInstance().displayImage(
							Constants.BadiDownImgUrl
									+ "/"
									+ logReadingDanji_Model.getJoinuser()
											.get(j).getHead()
									+ Constants.appPhoto4img, iv, options);

				} catch (Exception e) {
					// TODO: handle exception
				}
				holder.canjiazhehead.addView(view);
			}
		}

		// 添加城市
		if (logReadingDanji_Model.getZhan_num() != null)
			for (int i = 0; i < logReadingDanji_Model.getZhan_num().size(); i++) {
				// AddCity(""
				// + logReadingDanji_Model.getZhan_num().get(i)
				// .getZhan_name(), holder.ll_zhanName);

				Utils.AddCity(getActivity(), ""
						+ logReadingDanji_Model.getZhan_num().get(i)
								.getZhan_name(), holder.ll_zhanName);
			}
		// 以下是评论
		holder.admire.setText("" + logReadingDanji_Model.getAdmire());
		holder.discuss.setText("" + logReadingDanji_Model.getDiscuss());
		holder.share.setText("" + logReadingDanji_Model.getShare());
		// holder.title.setText(""+logReadingDanji_Model.getTitle());
		title = logReadingDanji_Model.getTitle();
		// 赞的好友
		if (logReadingDanji_Model.getAdmire_user() != null) {
			for (int i = 0; i < logReadingDanji_Model.getAdmire_user().size(); i++) {
				if (i == 0)
					holder.zanPeople.setText(""
							+ logReadingDanji_Model.getAdmire_user().get(i)
									.getNickName());
				else
					holder.zanPeople.setText(""
							+ holder.zanPeople.getText().toString()
							+ "、"
							+ logReadingDanji_Model.getAdmire_user().get(i)
									.getNickName());
			}
		} else {
			holder.all_zan_people.setVisibility(View.GONE);
		}

		// 一个特效而已
		holder.tuxian1.setSelected(true);

		//
		if (logReadingDanji_Model.getImg() != null) {
			final Gridview3Adapter g3 = new Gridview3Adapter(getActivity(),
					logReadingDanji_Model.getImg());
			holder.picture_gridView.setNumColumns(3);
			holder.picture_gridView.setAdapter(g3);
			holder.picture_gridView
					.setOnItemClickListener(new OnItemClickListener() {

						@Override
						public void onItemClick(AdapterView<?> arg0, View view,
								int position, long arg3) {
							List<BrowseAllPhoto_Model> mlistss = new ArrayList<BrowseAllPhoto_Model>();

							for (int i = 0; i < g3.getCount(); i++) {
								BrowseAllPhoto_Model models = new BrowseAllPhoto_Model();
								Img img = (Img) g3.getItem(i);
								models.setPath(img.getPath());
								models.setId(img.getId());
								mlistss.add(models);
							}
							Intent intent = new Intent(getActivity(),
									PicturePreviewActivity.class);
							intent.putExtra("picture_list",
									(Serializable) mlistss);
							intent.putExtra("picture_postion", position);
							startActivity(intent);
						}
					});
		}

		if (is_praise == true) {
			holder.iv_zan.setSelected(true);
			holder.iv_zan.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					if (!Utils.getUid(getActivity()).equals("")) {
					} else {
						Utils.showMessage(getActivity(), getResources()
								.getString(R.string.l_xb10));
					}

				}
			});
		} else {
			holder.iv_zan.setSelected(false);
			holder.iv_zan.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					if (!Utils.getUid(getActivity()).equals("")) {

						dianzan(getActivity(), Utils.getUid(getActivity()),
								aid, f_uid, "record_article");
					} else {
						Utils.showMessage(getActivity(), getResources()
								.getString(R.string.l_xb10));
					}
				}
			});
		}

		holder.biaoqing.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(),
						SinaExpressionActivity.class);
				getActivity().startActivityForResult(intent,
						PinLunGYAdapter.BIAO_QING);
			}
		});

		// //发送
		// holder.send.setOnClickListener(new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// //要发送的内容
		// String content=holder.send_content.getText().toString().trim();
		// sendMessage(Utils.getUid(getActivity()), uid, aid, "record_article",
		// content);
		// }
		// });
	}

	/**
	 * 用户评论使用接口 提交方式GET
	 * 
	 * @param $uid
	 *            ;//评论者的id @param $buid;//被评论者的id
	 * @param $conId
	 *            ;//被评论的内容id @param $type ;// 被评论类型activity club humor_trends
	 *            photo photo_img record_article
	 * @param $content
	 *            ;//评论内容
	 */
	public void sendMessage(final String uid, final String buid,
			final String conId, final String type, final String contents) {
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				String content = Utils.getRequest(Constants.BadiUrl
						+ "user_discuss?uid=" + uid + "&buid=" + buid
						+ "&conId=" + conId + "&type=" + type + "&content="
						+ contents);
				if (content != null) {
					// ("数据是：" + content);
					Results results = Utils.checkResult_NNN(getActivity(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
						//
						try {

							if (results.isRet() == true) {
								handler.sendEmptyMessage(5);
							} else {
								handler.sendEmptyMessage(6);
							}
						} catch (Exception e) {
							// TODO Auto-generated catch block

						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}

			}
		});
	}

	/**
	 * 删除单记
	 */
	private void delete_article() {
		// TODO Auto-generated method stub
		Utils.showPrgress(getActivity());
		new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				// uid是操作用户的id
				String content = Utils.getRequest(Constants.BadiUrl
						+ "delete_article?aid=" + aid + "&uid=" + uid);
				if (content != null) {
					Results results = Utils.checkResult_NNN(getActivity(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
						// ("结果是:" + results.getRetmsg());
						try {
							Message msg = new Message();
							msg.what = 4;
							Bundle bun = new Bundle();
							bun.putString("message", results.getRetmsg());
							bun.putBoolean("ret", results.isRet());
							msg.setData(bun);
							handler.sendMessage(msg);
						} catch (Exception e) {
							// TODO Auto-generated catch block

						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
				}
				handler.sendEmptyMessage(1);
			}
		}).start();
	}

	static class ViewHolder {
		public ImageView xiala;
		public ImageView iv_zan;
		public LinearLayout all_zan_people;
		public ImageView lshare;
		public GridView picture_gridView;
		public ListView listview_pinlun;
		public TextView content;// 内容
		public TextView bianji;// 编辑
		public TextView delete;// 删除
		public ImageView tuxian1;// 线
		public TextView admire;// 赞
		public TextView discuss;// 评论
		public TextView share;// 分享
		public TextView zanPeople;// 赞的人

		public TextView timeandcolleat;
		public LinearLayout canjiazhehead;// 参加者头像
		public ImageView head;// 发表用户头像
		public Button is_vote;// 是否可以投票 1表示可以 0 不可以
		public TextView canjiarenshu;// 参加人数
		public TextView vote;// 目前的票数
		public TextView uid;// 发表用户的id
		public TextView r_time;// 记录发表的时间
		public TextView j_time;// 记录时间距今天多少
		public TextView collect;// 被收藏的次数
		public TextView typeName;// 记录的标签名字 格式
									// $typeName1,$typeName2,$typeName3,$typeName4,$typeName5
		public TextView p_num;// @的人数
		public List<Record_Info_Model_1> acticle;// 记
		// **
		// startTimeandendTime
		// 下面的是记的
		public TextView startTimeandendTime;
		// 第几记
		public TextView dijiji;
		public NetworkImageView image;
		public LinearLayout ll_zhanName;
		public TextView title;
		// 我要发送的内容
		public EditText send_content;
		// 发送按钮
		public Button send;

		public ImageView biaoqing;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_logreadingdanji, null);

		holder = new ViewHolder();// ll_share

		initViewID(view, holder);

		return view;
	}

	public static LogReadingDanjiFragment0 getInstance() {
		if (logReadingDanjiFragment0 == null) {
			return new LogReadingDanjiFragment0();
		}
		return logReadingDanjiFragment0;
	}

	/**
	 * 设置标题
	 * 
	 * @param set
	 */
	public void setRecordTitle(setActivityView set) {
		set.setRecordData(logReadingDanji_Model);
	}

	public interface setActivityView {
		void setRecordData(LogReadingDanji_Model logReadingDanji_Model);
	}

	/**
	 * 点赞 接口名称 praise_operate 用户的点赞人的id 提交方式$GET
	 * 
	 * @param $uid
	 *            ;//点赞人的id
	 * @param $nid
	 *            ;//被操作内容的Id
	 * @param $nuid
	 *            ;//内容所属人id
	 * @param $type赞的类型
	 *            （record_article，club，humor_trends，photo，activity）
	 * @param hander
	 *            ;
	 * @param Success
	 *            ;成功
	 * @param defalt
	 *            ;失败
	 */
	public void dianzan(final Context context, final String uid,
			final String nid, final String nuid, final String type) {
		// Utils.showPrgress(context);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {

			@Override
			public void run() {

				String content = Utils.getRequest(Constants.BadiUrl
						+ "praise_operate?uid=" + uid + "&nid=" + nid
						+ "&nuid=" + nuid + "&type=" + type);
				//
				// + "type=" + type);
				// ("数据是：" + content);
				if (content != null) {
					// ("数据是：" + content);
					Results results = Utils.checkResult_NNN(context, content);
					if (results != null && !results.getRetmsg().equals("null")) {
						//
						try {
							// int c=pos;
							Message msg = new Message();

							if (results.isRet() == true) {
								msg.what = 8;
							} else {
								msg.what = 9;
							}
							handler.sendMessage(msg);
						} catch (Exception e) {

						}
					} else {
						handler.sendEmptyMessage(1);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});

	}

	/**
	 * 查看某用户是否赞过某条动态/信息 POST
	 * 
	 * @param $uid
	 *            //登录用户ID(不用传)
	 * @param $type
	 *            //（必需）动态类型（humor_trends：心情动态，photo：相册，photo_img：图片，
	 *            record_article：记录（记），club：俱乐部，activity：活动）
	 * @param $contentId
	 *            （必需）动态内容ID return boolean
	 */
	public void is_praise(String type, String contentId)// commonality/;
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", Utils.getUid(getActivity()));
		map.put("type", type);
		map.put("contentId", contentId);
		CommonUtils.CommomPostfunction(getActivity(), Constants.BadiUrl_1
				+ "commonality/is_praise", map, handler, 1, 3, 10, 11);
	}

	public void getSend_Content(getEditText get) {
		get.getEditText(holder.send_content);

	}

	public interface getEditText {
		void getEditText(EditText send_content);
	}
}
